#include "Graphics/sdlfx.h"


using namespace Jin;

bool InitSDLFramework() {
	try {
		static SDLFramework sdlfx;
		return true;
	}
	catch (const std::exception& e) {
		printf("Init SDLFramework error! '%s'\n", e.what());
		return false;
	}
}

int main() {
	if (InitSDLFramework()) {
		auto& sdlfx = SDLFramework::GetInstance();
		printf("SDL version: %d.%d.%d\n", sdlfx.version.major, sdlfx.version.minor, sdlfx.version.micor);

		auto num = sdlfx.GetNumRenderDrivers();
		for (int index = 0; index < num; ++index) {
			printf("%s\n", sdlfx.GetRenderDriverName(index).data());
		}

		SDLWindow window(_T("testSDLFX"), 800, 600, 0);
		if (window) {
			printf("SDLWindow create success.\n");

			sdlfx.SetFPS(200);

			sdlfx.onEvent = [](EventData& event) {
				printf("event.type : %d\n", event.type);
				return true;
			};

			sdlfx.onFPS = [&sdlfx, &window](Uint32 fps) {
				window.SetTitle(std::format(_T("fps:{}, delta:{}"), fps, sdlfx.deltaTime));
			};

			bool runing = true;
			while (runing) {
				sdlfx.CountFrame();
				while (sdlfx.PollEvent()) {
					if (sdlfx.event.type == SDL_EVENT_QUIT) {
						runing = false;
						break;
					}
				}
			}

		}
	}
	return 0;
}